package org.activiti.explorer.servlet.modeler;

import javax.servlet.ServletContext;

import org.activiti.explorer.filter.ExplorerFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

//@Configuration
//@ComponentScan({
//    "org.activiti.rest.service",
//    "org.activiti.rest.exception", 
//    })
//@EnableAsync
public class ModelerServletConfiguration extends WebMvcConfigurationSupport {

  private final Logger log = LoggerFactory.getLogger(ModelerServletConfiguration.class);

  //@Bean(name="ModelerServlet")
  public ServletRegistrationBean modelerServlet(DispatcherServlet dispatcherServlet){
      ServletRegistrationBean bean = new ServletRegistrationBean(dispatcherServlet);
      bean.setName("ModelerServlet");
      //bean.setServlet(new DispatcherServlet());
      //bean.getUrlMappings().clear(); //后续需要考虑是否需要清理
      bean.addUrlMappings("/service/*");
      bean.setLoadOnStartup(1);
      bean.setAsyncSupported(true);
      //servletContext();
      return bean;
  }

  public ServletContext servletContext(){
      ServletContext servletContext = getServletContext();
      servletContext.addFilter("/activiti-explorer/*", ExplorerFilter.class);
      //servletContext.addFilter("/service/*", JsonpCallbackFilter.class);
      servletContext.addListener(RequestContextListener.class);
      //servletContext.addListener(WebConfigurer.class);
      return servletContext;
  }
  
}
